package cn.edu.xmu.restfuldemo.controller;

import cn.edu.xmu.restfuldemo.util.Common;
import cn.edu.xmu.restfuldemo.util.ReturnObject;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.edu.xmu.restfuldemo.service.GoodsService;

/**
 * 商品控制器
 * @author RenJieZheng
 */
@Api(value = "商品API", tags = "商品API")
@RestController /*Restful的Controller对象*/
@RequestMapping(value = "/goods", produces = "application/json;charset=UTF-8")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/{id}")
    public Object getGoodsSkuById(@PathVariable("id") Long id) {
        ReturnObject returnObject = goodsService.findGoodsRetVoByGoodsId(id);
        return Common.getRetObject(returnObject);
    }

    @GetMapping("/{id}/redis")
    public Object getGoodsSkuByIdUsingRedis(@PathVariable("id") Long id) {
        ReturnObject returnObject = goodsService.findGoodsRetVoByGoodsIdUsingRedis(id);
        return Common.getRetObject(returnObject);
    }

}
